//
//  PersonalViewController.m
//  Fragrance
//
//  Created by dllo on 15/5/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "PersonalViewController.h"
#import "LeftViewController.h"
#import "RightViewController.h"
#import "CenterViewController.h"
#import "HHViewController.h"
@interface PersonalViewController ()

@property (nonatomic) BOOL leftShow;
@property (nonatomic, retain) LeftViewController *left;
@property (nonatomic, retain) RightViewController *right;
@property (nonatomic, retain) UITabBarController *tab;


@end

@implementation PersonalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view setBackgroundColor:[UIColor purpleColor]];
    
    UIImage *imageBg = [UIImage imageNamed:@"beijingtu1"];
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    imageV.image = imageBg;
    [self.view addSubview:imageV];
    [imageV release];
    
    self.left = [[LeftViewController alloc] init];
    [self addChildViewController:_left];
    [self.view addSubview:_left.view];
    [_left.view setFrame:CGRectMake(-self.view.frame.size.width, 0, 250, self.view.frame.size.height)];
    [_left release];
    
    self.right = [[RightViewController alloc] init];
    [self addChildViewController:_right];
    [self.view addSubview:_right.view];
    [_right.view setFrame:CGRectMake(self.view.frame.size.width, 0, 250, self.view.frame.size.height)];
    [_right release];
    
    
    
    
    // center
    HHViewController *center = [[HHViewController alloc] init];
    self.tab = [[UITabBarController alloc] init];
    [center setBlock:^{
        
        [UIView animateWithDuration:0.8 animations:^{
            _left.view.frame = CGRectMake(0, 0, 250, self.view.frame.size.height);
            [_tab.view setFrame:CGRectMake(250, 80, 250, self.view.frame.size.height - 160)];
            
        } completion:^(BOOL finished) {
            UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(250, 0, self.view.frame.size.width - 250, self.view.frame.size.height)];
            [rightView setBackgroundColor:[UIColor clearColor]];
            [self.view addSubview:rightView];
            [rightView release];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftHidden:)];
            [rightView addGestureRecognizer:tap];
            [tap release];
            
        }];
        
    }];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:center];
    
    
    _tab.viewControllers = @[nav];
    
    [self addChildViewController:_tab];
    [self.view addSubview:_tab.view];
    
    [nav release];
    [center release];
    
    
}


- (void)leftHidden:(UITapGestureRecognizer *)tap
{
    
    [UIView animateWithDuration:0.25 animations:^{
        [_left.view setFrame:CGRectMake(-self.view.frame.size.width, 0, 250, self.view.frame.size.height)];
        
        [_tab.view setFrame:[[UIScreen mainScreen] bounds]];
    } completion:^(BOOL finished) {
        
    }];
    
}

    
    




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
